<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>北京站智能网格化管理系统</title>
    <link rel="stylesheet" type="text/css" href="../lib/css/common.css">
    <link rel="stylesheet" href="../lib/css/iconFont/iconfont.css">
    <link rel="stylesheet" href="../lib/css/pagination.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/station.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/jquery.datetimepicker.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/newcount.css">  
</head>
<body>
<div class="station_grid wraper">
    <div class="searchwrap">
        <!-- 日期时间 -->
        <div class="searchelm searchtime1">
            <input type="text" id="datetimepicker" class="search_control" name="ptime_start">
            <input type="text" id="datetimepicker2" class="search_control" name="ptime_end">
            <div class="select2_wrap" style="min-width:15rem;max-width:60%;">
                <select name="wxdep" id="wxdep" class="search_control wxdep" style="width:100%">
                </select>
            </div>
            <div class="select2_wrap" style="min-width:15rem;max-width:60%;">
                <select name="post" id="post" class="search_control post" style="width:100%">
                </select>
            </div>
            <!-- <select name="wxdep" id="wxdep" class="select_option wxdep" style="width:12rem;">
                <option value="1" checked>防修车间</option>
                <option value="2">信息化车间车间</option>
            </select> -->
            <input type="button" value="查询" id="lookUp1" class="lookUp"/>
        </div>
        <!-- 图表导出 切换 -->
        <div class="tabbar clearfix">
            <ul class="tab">
                <li class="tab_li tab_li_click" data-rel="1"><i class="icon iconfont icon-biaoge"></i>表格</li>
                <li class="tab_li" id="export_file" data-rel="2"><i class="icon iconfont icon-daochu"></i>导出</li>
            </ul>
        </div> 
    </div>
    <!-- echarts统计图表 -->
    <div class="main_content">
        <!-- 人员表格 -->
        <div class="station_shaow_detail nan">
            <table class="station_shaow_detail_table">
                <caption style="font-size: 2.4rem;">设备部门维修人员合格率</caption>
            </table>
                <div class="M-box1" style="font-size:10px;text-align:center;" id="page_string">
            </div>
        </div>
        <div class="lds-css block">
            <div class="lds-dual-ring">
                <div></div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="../lib/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../lib/js/base.js"></script>
<script type="text/javascript" src="../lib/js/datetimepicker.js"></script>
<script type="text/javascript" src="../lib/js/jquery.pagination.js"></script>
<script type="text/javascript" src="../lib/js/select2.full.min.js"></script>
<script type="text/javascript" src="../lib/js/count.js"></script>
<script  type="text/javascript">
    
//查询
var page = 1,postDep='0'
$("#lookUp1").click(function () {
    var _data = {
        'page':page,
        'start':$('#datetimepicker').val(),
        'end':$('#datetimepicker2').val(),
        'department_id': $('#wxdep').val()=='none'?"":$('#wxdep').val(),
        'posts':$('.post').val()
        // 'time':<?php echo time();?>,
    };
    devicePostRepairTable(_data)
});
function findDetail(e,ids){
    var _tr = $(e).parents('tr'),_ids = ids
    if($(e).hasClass('black_act')){
        $(e).removeClass('black_act') 
        $(e).addClass('black2_act') 
        _tr.after('<tr class="shaow_detail_title count_tr listalign listnone listloading"><td></td><td colspan="10" stylt="text-align:center">加载中。。。</td></tr>')
        $.ajax({
            type: "POST",
            url: serverUrl.base+serverUrl.count+'repair_info',
            data:{
                start:$('#datetimepicker').val(),
                end:$('#datetimepicker2').val(),
                user_id:_ids
            },
            cache: false,
            dataType: "json",
            success: function(res){
                if(res.code == '0'){
                    var _data=res.data
                    var _html=''
                    if(_data.length != 0){
                        var _trs = '<tr class="shaow_detail_title count_tr listalign list'+_ids+'"><td></td><td colspan="8" class="detailtable"></td></tr>'
                        _tr.after(_trs)
                        var _table = $('<table class="station_shaow_detail_table"></table>')
                        _table.appendTo($('.list'+_ids+ ' .detailtable'))
                        _table.createTable({data:_data,columns:[
                            {name:'设备名称',field:'device_name',w:'4rem'},
                            {name:'维修完成时间',field:'task_donetime',w:'4rem'}
                            // {name:'任务完成情况',field:'status',w:'4rem'},
                        ]})
                           
                    }else{
                        _html = '<tr class="shaow_detail_title count_tr listalign listnone"><td></td><td colspan="10" stylt="text-align:center">无数据</td></tr>'
                        _tr.after(_html)
                    }
                    $(e).removeClass('black_act') 
                    $(e).addClass('black2_act') 
                }else{
                    _html = '<tr class="shaow_detail_title count_tr listalign listnone"><td></td><td colspan="10" stylt="text-align:center">无数据</td></tr>'
                    _tr.after(_html)
                }
            },
            complete:function(res){
                _tr.nextAll('.listloading').remove();
            }
        })
    }else{

        $(e).removeClass('black2_act') 
        $(e).addClass('black_act') 
        _tr.nextAll('.list'+_ids).remove();
        _tr.nextAll('.listnone').remove();
    }
    
}
//表格
function devicePostRepairTable(data){
    
    $('.lds-css').addClass('block')
    var _data = data
    $.ajax({
        url: serverUrl.base+serverUrl.count+'repair_pass_table',
        type:"POST",
        data: _data,
        dataType:"json",
        success: function (res) {
            $('.lds-css').removeClass('block')
            // 根据数据库取到结果拼接现在结果
            var _data = res.data
            $('.station_shaow_detail_table').createTable({data:_data,columns:[
                {name:'序号',field:'',ids:1,w:'4rem'},
                {name:'维修人',field:'user_name',w:'4rem'},
                {name:'维修岗位',field:'post_name',w:'10rem'},
                {name:'所在部门',field:'department_name',w:'10rem'},
                {name:'设备维修次数',field:'all_num',w:'8rem'},
                {name:'设备合格次数',field:'pass_num',w:'8rem'},
                {name:'维修合格率',field:'pass_percent',w:'8rem'},
                {name:'详情',field:'user_id',w:'10rem',cls:'list_resource',render:function(index,elm,data,tr){
                    var _btn = '<span class="black1 black_act" onclick="findDetail(this,'+elm+')">查看详情</span></td>',$btn = $(_btn)
                    return _btn
                }}
            ]})
            $("#page_string").html(res.result_page);
            
        }
    });
}

var page = 1 ; 
function common_request(elm){
    if(arguments[0]){
        page = arguments[0]
    }else{
        page = 1
    }
   $("#lookUp1").trigger('click') 
}
common_request()
//查询
function search_(){
    page = 1 ;
    common_request(1);  
}
//tab初始化
$('.tab .tab_li').each(function(index,elm){
    //console.log(index,elm)
    $(this).data('val',index)
})
//图表切换后的操作
$('.tab_li').on('click',function(elm){
    var $this = $(this)
    var _ids = $this.data('rel')?$this.data('rel'):$this.index()
    if(_ids== '1'){
        $(".educe").addClass("addli");
    }else if(_ids== '2'){
        //导出按钮
        var _data = {
            'page':page,
            'start':$('#datetimepicker').val(),
            'end':$('#datetimepicker2').val(),
            'department_id': $('#wxdep').val()=='none'?"":$('#wxdep').val(),
            'posts':$('.post').val()==null?"":$('.post').val()
            // 'time':<?php echo time();?>,
        };
        var _url=serverUrl.base + serverUrl.countD + 'repair_pass_table?start='+encodeURIComponent(_data.start)+'&end='+encodeURIComponent(_data.end)+'&department_id='+encodeURIComponent(_data.department_id) + '&posts='+encodeURIComponent(_data.posts)
        window.location.href = _url;return;
    }
})
//设备管理部门
$('.wxdep').rpSelect({url:serverUrl.base+serverUrl.count+serverUrl.dep,multiple:false,placeholder:'请选择设备管理部门',hasAll:true})
$('.wxdep').on('change',function(){
    var _val = $(this).val()  
    $('.post').find('option').remove()
    $('.post').select2('destroy')
    if(_val == 'none'){
        _val=''
    }
    $('.post').rpSelect({url:serverUrl.base+serverUrl.post+'post_list',data:{department_id:_val},multiple:true,placeholder:'请选择维修岗位'})
})
$('.post').rpSelect({url:serverUrl.base+serverUrl.post+'post_list',multiple:true,placeholder:'请选择维修岗位'})

</script>
</body>

</html>

